﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace SLConnectedWebPart.SLConConsumerPart
{
    [ToolboxItemAttribute(false)]
    public class SLConConsumerPart : WebPart
    {
        ISPListItem _provider = null;
        Label _lbl = null;


        protected override void CreateChildControls()
        {

            try
            {
                _lbl = new Label();

                if (_provider != null)
                {
                    if (_provider.Name != null)
                    {
                        _lbl.Text = _provider.Name + " was selected.";
                    }
                    else
                    {
                        _lbl.Text = "Nothing was selected.";
                    }
                }
                else
                {
                    _lbl.Text = "No Provider Web Part Connected.";
                }

                this.Controls.Add(_lbl);
            }
            catch (Exception ex)
            {
                this.Controls.Clear();
                this.Controls.Add(new LiteralControl(ex.Message));
            }
        }

        [ConnectionConsumer("ListItem Name and ID")]
        public void ThisNameDoesNotMatter(ISPListItem providerInterface)
        {
            _provider = providerInterface;
        }

    }
}
